﻿// SmartCPPWindow.xaml.cs
//
// Copyright 2009 Sergey Mechtaev
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation.


using System;
using System.IO;
using System.Windows;
using SmartCPP.Core.Preprocessor;
using SmartCPP.Core.Util;

namespace SmartCPP.GUI
{
  /// <summary>
  /// Interaction logic for SmartCPPWindow.xaml
  /// </summary>
  public partial class SmartCPPWindow : Window
  {
    public SmartCPPWindow()
    {
      InitializeComponent();
    }

    private String currentFileName = "";
    private String currentHistory = "";

    
    private void openButton_Click(object sender, RoutedEventArgs e)
    {
      var inputReader = File.OpenText(fileTextBox.Text);
      var fileContent = inputReader.ReadToEnd() + "\n";
      currentFileName = fileTextBox.Text;
      inputDocumentViewer.Text = fileContent;
      currentHistory = "";
    }

    private void runButton_Click(object sender, RoutedEventArgs e)
    {
      var result = Preprocessor.start(inputDocumentViewer.Text.ToCharArray(), currentFileName);
      outputDocumentViewer.Text = result.Item1;
      currentHistory = Printing.print_history(result.Item2);
    }

    private void preimageButton_Click(object sender, RoutedEventArgs e)
    {

    }

    private void browseButton_Click(object sender, RoutedEventArgs e)
    {

    }

    private void historyButton_Click(object sender, RoutedEventArgs e)
    {
      outputDocumentViewer.Text = currentHistory;
    }
  }
}
